package handler

import (
	"360video/video-api/api/reponse"
	"360video/video-api/api/request"
	"360video/video-api/config"
	"360video/video-api/pkg"
	__ "360video/video-srv/handler/proto"
	"github.com/gin-gonic/gin"
	"log"
)

func VideoAdd(c *gin.Context) {
	req := request.VideoAdd{}
	if c.ShouldBind(&req) != nil {
		reponse.Error(c, "绑定失败")
		return
	}
	r, err := config.VideosClient.VideoAdd(c, &__.VideoAddReq{
		UserId:  int64(req.UserId),
		Titer:   req.Titer,
		Message: req.Message,
		Static:  req.Static,
		Address: req.Address,
		Year:    req.Year,
		Image:   req.Image,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	if !pkg.NewBaidu(req.Titer) {
		reponse.Error(c, "词汇中含有敏感词")
		return
	}
	reponse.Success(c, "视频添加成功", __.VideoAddResp{
		Id: r.Id,
	})
}
